<?php
/**
 * Created by PhpStorm.
 * User: Mysic
 * Date: 2020/10/29
 * Time: 18:11
 */

namespace app\mocks\controller;


use app\common\library\MysicLog;
use app\mocks\extend\MockWeChatPay;
use think\Env;
use think\Controller;
use think\Request;

class Order extends Controller
{
    protected $log;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->log = MysicLog::instance();
    }

    public function buyNow()
    {
        $request = $this->request;
        $post['shop_id'] = $request->post('shop_id',0);
        $post['phone'] = $request->post('phone','');
        $post['coupon_id'] = $request->post('coupon_id','');
        $post['is_use_points'] = $request->post('is_use_points','');
        $post['is_use_balance'] = $request->post('is_use_balance','');
        $post['remark'] = $request->post('remark','');
        $post['goods_id'] = $request->post('goods_id',0);
        $post['goods_num'] = $request->post('goods_num',0);
        $post['goods_sku_id'] = $request->post('goods_sku_id',0);;
        $post['wxapp_id'] = $request->post('wxapp_id',1);
        $post['token'] = $request->post('token','');
        $request->create(Env::get('app.host') . '/api/order/buyNow', 'post', $post);
        $controller = new \app\api\controller\Order();
        $createOrderRet = $controller->buyNow();
        $this->log->save();
        $payNotifyRet = false;
        if($createOrderRet['code'] ?? false) {
            $payNotifyRet = MockWeChatPay::instance()->doPayNotify();
        }
        dd($payNotifyRet);
    }

    public function facePay()
    {
        $post['price'] = $this->request->post('price',1);
        $post['couponId'] = $this->request->post('couponId', 0);
        $post['message'] = $this->request->post('message', '');
        $post['discount'] = $this->request->post('discount', 0);
        $post['pay_way'] = $this->request->post('pay_way', 20);
        $post['dis_type'] = $this->request->post('dis_type', 2);
        $post['wxapp_id'] = $this->request->post('wxapp_id');
        $post['token'] = $this->request->post('token');
        $this->request->create(Env::get('app.host') . '/api/order/payFace', 'post', $post);
        $controller = new \app\api\controller\Order();
        $createOrderRet = $controller->payFace($post['price'],$post['couponId'],$post['message'],$post['discount'],$post['pay_way'],$post['dis_type']);
        $payNotifyRet = false;
        if($createOrderRet['code'] ?? false) {
            $payNotifyRet = MockWeChatPay::instance()->doPayNotify();
        }
        dd($payNotifyRet);
    }

    public function vipCard()
    {
        $post['card_id'] = $this->request->post('card_id');
        $post['wxapp_id'] = $this->request->post('wxapp_id');
        $post['token'] = $this->request->post('token');
        $this->request->create(Env::get('app.host') . '/api/vipcard/submit', 'post', $post);
        $controller = new \app\api\controller\Vipcard();
        $ret = $controller->submit();
        $payNotifyRet = false;
        if($ret['code'] ?? false) {
            $payNotifyRet = MockWeChatPay::instance()->doPayNotify();
        }
        dd($payNotifyRet);
    }
}